/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;

/**
 * @author Mr Bao
 */
public class UpAnh extends MIDlet {

    public static int UserId = 0;
    public Display display;
    public Client client;
    private HomeMain homeMain;
    private ViewAlbum viewAlbum;
    private ViewImage viewImage;
    private ViewImageName viewImageName;
    private ViewImageNameNew viewImageNameNew;
    private FileBrowser fileBrowser;
    public int albumIndex;
    private UploadImage uploadImage;
    private UploadChose uploadChose;
    private Login login;

    public UpAnh() {
        client = new Client(this);
        display = Display.getDisplay(this);
    }

    public void startApp() {
        DisplayLogin();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }

    public void Exit() {
        client.Exit();
        destroyApp(false);
    }

    public void DisplayUpAnhChose() {
        if (uploadChose == null) {
            uploadChose = new UploadChose(this);
        }
        display.setCurrent(uploadChose);
    }

    public void DisplayException(Exception ex) {
        Alert alert = new Alert("Exception");
        alert.setString(ex.getMessage());
        alert.setType(AlertType.ERROR);
        display.setCurrent(alert);
    }

    public void DisplayHomeMain() {
        if (homeMain == null) {
            homeMain = new HomeMain(this);
        }
        display.setCurrent(homeMain);
    }

    public void DisplayError(String type) {
    }

    public void DisplayRegister() {
        Register register = new Register(this);
        display.setCurrent(register);
    }

    public void DisplayViewImage() {
        if (viewImage == null) {
            viewImage = new ViewImage(this);
        }
        display.setCurrent(viewImage);
    }

    public void DisplayBrowser() {
        fileBrowser = new FileBrowser(this, 1);
        fileBrowser.ShowCurrDir();
    }

    public void DisplayViewBrowser() {
        fileBrowser = new FileBrowser(this, 0);
        fileBrowser.ShowCurrDir();
    }

    public void DisplayViewAlbum() {
        viewAlbum = new ViewAlbum(this);
        display.setCurrent(viewAlbum);
    }

    public void DisplayViewAlbumBack() {
        display.setCurrent(viewAlbum);
    }

    public void DisplayViewImageName(String albumName, int indexAlbum) {
        viewImageName = new ViewImageName(this, albumName, indexAlbum);
        display.setCurrent(viewImageName);
    }

    public void DisplayViewImageNameBack() {
        display.setCurrent(viewImageName);
    }

    public void DisplayViewImageNameNew() {
        viewImageNameNew = new ViewImageNameNew(this);
        display.setCurrent(viewImageNameNew);
    }

    public void DisplayViewImageNameNewBack() {
        display.setCurrent(viewImageNameNew);
    }

    public void DisplayImageView(int selectedIndex, String name) {
        ImageView imageView = new ImageView(this, selectedIndex, name);
        display.setCurrent(imageView);
    }

    public void DisplayImageViewNew(int selectedIndex) {
        ImageViewNew imageView = new ImageViewNew(this, selectedIndex);
        display.setCurrent(imageView);
    }

    public void DisplayAddAlbum() {
        AddNewAlbum addNewAlbum = new AddNewAlbum(this);
        display.setCurrent(addNewAlbum);
    }

    public void DisplayUploadImage() {
        uploadImage = new UploadImage(this);
        display.setCurrent(uploadImage);
    }

    public void DisplayUploadImageBack() {
        display.setCurrent(uploadImage);
    }
    private Camera camera;

    public void DisplayCamera() {
        if (camera == null) {
            camera = new Camera(this);
        }
        display.setCurrent(camera);
    }

    public void DisplayLogin() {
        if (login == null) {
            login = new Login(this);
        }
        display.setCurrent(login);
    }

    public void DisplayUpAnhForm(byte[] images, boolean isCamera) {
        UpAnhForm upAnhForm = new UpAnhForm(this, images, isCamera);
        display.setCurrent(upAnhForm);
    }

    public void DisplayTimkiem() {
        Timkiem timkiem = new Timkiem(this);
        display.setCurrent(timkiem);
    }

    public void DisplayBrowserBack() {
        fileBrowser.ShowCurrDir();
    }
}
